
package lishaole;

import java.util.Arrays; 
import java.util.Scanner;
public class java4 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		Person[] person=new Person[n];
		String name;
		int age;
		for (int i = 0; i <n; i++) {
			name=sc.next();
			age=sc.nextInt();		
			person[i]=new Person(name,age);
		}
		Arrays.sort(person);
		for (Person person2 : person) {
			System.out.println(person2);
			
		}
		System.out.println(Arrays.toString(Person.class.getInterfaces()));
		sc.close();
	}
}
class Person implements Comparable<Person>{
	private String name;
	private int age;
	
	public Person(String name,int age){
		this.name = name;
		this.age = age;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return name+"-"+age;
	}
	@Override
	public int compareTo(Person o) {
		int x=this.name.compareTo(o.name);
		if(x!=0)
			return x;
		
		
		return this.getAge()-o.getAge();
	}
}

